﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using NLBS.Entity;
using NLBS.Data;
using NLBS.Provider;
using System.IO;
using System.Reflection;

namespace NLBS
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            //计数器初始化
            Application.Lock();//加锁
            Application["TotalCount"] = 0;
            Application["OnLine"] = 0;
            Application.UnLock();
            //解锁
            // Mono does not use "__code" as the name of the App_Data assembly.
            // Rather, it uses "App_Code", which is case sensitive!
            //string assemblyName = "__code";
            //Type t = Type.GetType("Mono.Runtime");
            //if (t != null)
            //    assemblyName = "App_Code";

            //Assembly a = Assembly.Load(assemblyName);
            //Type[] types = a.GetTypes();

            //foreach (Type type in types)
            //{
            //    object[] attributes = type.GetCustomAttributes(typeof(ExtensionAttribute), false);
            //    foreach (object attribute in attributes)
            //    {
            //        if (ExtensionManager.ExtensionEnabled(type.Name))
            //        {
            //            a.CreateInstance(type.FullName);
            //        }
            //    }
            //}

        }

        protected void Session_Start(object sender, EventArgs e)
        {
           // NLBS.Framework.Global.InsertVisitor();
            Session.Timeout = 5;
            //计数器加1
            Application.Lock();
            Application["TotalCount"] = Int32.Parse(Application["TotalCount"].ToString()) + 1;
            Application["OnLine"] = Int32.Parse(Application["OnLine"].ToString()) + 1;
            Application.UnLock();
        }

        

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
        }

        protected void Application_Error(object sender, EventArgs e)
        {
        }

        protected void Session_End(object sender, EventArgs e)
        {
            //访问人数减一
            Application.Lock();
            Application["OnLine"] = Int32.Parse(Application["OnLine"].ToString()) - 1;
            Application.UnLock();
        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}